﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Acme.ShopStore.Shops
{
    public class ShopAppService :
        CrudAppService<
            Shop, //The Book entity
            ShopDto, //Used to show books
            Guid, //Primary key of the book entity
            ShopQueryDto, //Used for paging/sorting
            CreateUpdateShopDto>, //Used to create/update a book
        IShopAppService //implement the IBookAppService  
    {

        public ShopAppService(IRepository<Shop, Guid> repository)
            : base(repository)
        {

        }

        //[Obsolete]
        //protected override IQueryable<Shop> CreateFilteredQuery(ShopQueryDto dto)
        //{
        //    return base.CreateFilteredQuery(dto).WhereIf(!string.IsNullOrEmpty(dto.ShopName), b => b.ShopName.Contains(dto.ShopName)).Where(s => s.IsShow.Equals(dto.IsShow));
        //}
        [Obsolete]
        protected override IQueryable<Shop> CreateFilteredQuery(ShopQueryDto infoDto)
        {
            if (!string.IsNullOrEmpty(infoDto.ShopName))
            {
                return base.CreateFilteredQuery(infoDto).Where(s => s.ShopName.Contains(infoDto.ShopName) && s.IsShows == infoDto.IsShows);
                //return base.CreateFilteredQuery(infoDto).WhereIf(!string.IsNullOrEmpty(infoDto.CommodityName), s => s.CommodityName.Contains(infoDto.CommodityName));
            }
            else
            {
                return base.CreateFilteredQuery(infoDto).Where(s => s.IsShows == infoDto.IsShows);
            }
        }
    }
}
